package com.payment.ktb.activity.main4;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.payment.ktb.Interface.HttpCallbackListener;
import com.payment.ktb.R;
import com.payment.ktb.activity.BaseActivity;
import com.payment.ktb.activity.TestActivity;
import com.payment.ktb.constants.HttpActions;
import com.payment.ktb.constants.HttpUrls;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.HttpUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by admin on 2017/10/12.
 */

public class UseInstructionsActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_useinstructions);
        ButterKnife.bind(this);
        initTitle("操作说明");

    }

    @OnClick({R.id.ll_useinstruction_one,R.id.ll_useinstruction_two,R.id.ll_useinstruction_three,R.id.iv_useinstructions_play})
    public void clickEvent(View view) {

        switch (view.getId()) {


            //实名认证
            case R.id.ll_useinstruction_one:
                startActivity(CertificationInstructionActivity.class);
                break;

            //绑定结算卡
            case R.id.ll_useinstruction_two:
                startActivity(BindSettleCardInstructionActivity.class);
                break;

            //收款
            case R.id.ll_useinstruction_three:
                startActivity(CashierInstructionActivity.class);
                break;

            //播放视频
            case R.id.iv_useinstructions_play:
                getAppInitState();
                break;


        }

    }


    public void getAppInitState() {


        progressDialogUtils.showProgress();

        //构造传输参数
        Map<String, String> map = new HashMap<String,String>();
        map.put("timestamp",String.valueOf(new Date().getTime()));

        //向服务器发送请求
        HttpUtils.HttpRequestByVollery(HttpUrls.URL, HttpActions.AppInitState, map, mQueue, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                progressDialogUtils.dismissProgress();
                try {
                    JSONObject jsonObject = new JSONObject(response);

                    Intent intent = new Intent(mContext,PlayVideoActivity.class);
                    intent.putExtra("videoUrl",jsonObject.optString("videoUrl"));
                    startActivity(intent);


                } catch (JSONException e) {
                    e.printStackTrace();
                    AlertDialogUtils.showAlertDialog(mContext, getResources().getString(R.string.json_parse_error));
                }
            }

            @Override
            public void onError(VolleyError volleyError) {
                progressDialogUtils.dismissProgress();
                AlertDialogUtils.showAlertDialog(mContext, volleyError.getMessage());
            }
        });


    }
}
